import {
    orderListApi
} from '@/api/order'
import AddressEdit from './components/address-edit.vue'
import Express from './components/express.vue'
export default {
    components: {
        AddressEdit,
        Express
    },
    data() {
        return {
            queryInfo: {
                query: '',
                pagenum: 1,
                pagesize: 10
            },
            orderList: [],
            total: 0
        }
    },
    created() {
        this.getOrderList()
    },
    methods: {
        async getOrderList() {
            const res = await orderListApi(this.queryInfo)
            if (res.meta.status !== 200) {
                return this.$message.error('获取订单列表失败！')
            }
            this.orderList = res.data.goods
            this.total = res.data.total
        },
        // 触发这个函数pagesize发生变化
        handleSizeChange(newSize) {
            this.queryInfo.pagesize = newSize
            this.getOrderList()
        },
        // 触发这个函数pagenum发生变化
        handleCurrentChange(newPage) {
            this.queryInfo.pagenum = newPage
            this.getOrderList()
        },
        // 搜索
        search() {
            if (this.queryInfo.query.trim() === '') return
            this.queryInfo.pagenum = 1
            this.getOrderList()
        },
        // 打开修改收货地址的对话框
        showAddressDialog(order) {
            // 方式一：可以通过$children属性获取所有的子组件
            // console.log(this.$children[2].openDialog())
            // 方式二：可以使用ref来获取
            this.$refs.addressEditRef.openDialog(order)
        },
        // 打开物流进度对话框
        showExpressDialog(order) {
            this.$refs.expressRef.openDialog(order)
        }
        /* test() {
            console.log('parent test')
        } */
    }
}